package com.qianyu.project.service.impl;

import com.qianyu.project.core.annotation.FlowBegin;
import com.qianyu.project.core.annotation.FlowEntry;
import com.qianyu.project.entity.MaterialContract;
import com.qianyu.project.entity.MaterialContractDetail;
import com.qianyu.project.mapper.MaterialContractMapper;
import com.qianyu.project.service.IMaterialContractDetailService;
import com.qianyu.project.service.IMaterialContractService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 材料合同 服务实现类
 * </p>
 *
 * @author gs
 * @since 2021-01-30
 */
@Service
public class MaterialContractServiceImpl extends ServiceImpl<MaterialContractMapper, MaterialContract> implements IMaterialContractService {

    @Autowired
    private MaterialContractMapper contractMapper;

    @Autowired
    private IMaterialContractDetailService detailService;
    /**
     *
     * description:  <br/>
     * author: lyz   <br/>
     * date: 2021/2/9 <br/>
     * params:  <br/>
     * return:
     */
    @Override
    @FlowBegin("material_contract")
    public void saveMaterialContract(@FlowEntry("id") MaterialContract contract, List<MaterialContractDetail> detailList) {
        contractMapper.insert(contract);
        detailList.forEach(e->{
            e.setContractId(contract.getId());
        });
        detailService.saveBatch(detailList);
    }
}
